package com.qilu.careprogram.service.impl;

import com.qilu.careprogram.dao.PatientExceptionDAO;
import com.qilu.careprogram.pojo.entity.PatientException;
import com.qilu.careprogram.service.PatientExceptionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class PatientExceptionServiceImpl implements PatientExceptionService {

    @Resource
    PatientExceptionDAO patientExceptionDAO;

    @Override
    public void insert(List<String> exceptionList, String hospitalNumber) {
        StringBuilder exceptions = new StringBuilder();
        for (String e : exceptionList) {
            exceptions.append(e);
            exceptions.append(",");
        }
        PatientException patientException = PatientException.builder()
                .hospitalNumber(hospitalNumber)
                .exception(exceptions.toString())
                .isProcessed(false)
                .createTime(LocalDateTime.now())
                .updateTime(LocalDateTime.now())
                .build();
        patientExceptionDAO.insert(patientException);

    }

    @Override
    public List<PatientException> getPatientExceptionList() {
        return patientExceptionDAO.getPatientExceptionList();
    }
}
